package smartagdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import smartagdemo.bean.HumidityData;
import smartagdemo.bean.LightData;
import smartagdemo.bean.TemperatureData;
import smartagdemo.bean.TestData;
import smartagdemo.service.ViewService;
import smartagdemo.service.impl.ViewServiceImpl;

import java.sql.Timestamp;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("SmartAG/view")
public class ViewController {
    @Autowired
    private ViewServiceImpl viewService;
    //测试数据查看
    @RequestMapping("/viewTest")
    public List<TestData> viewTest(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewTest(tDate1,tDate2);
    }
    //查询当日湿度
    @RequestMapping("/viewTodayHumidity")
    public List<HumidityData> viewHumidityDate(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewHumidityData(tDate1,tDate2);
    }
    //查询当日温度
    @RequestMapping("/viewTodayTemperature")
    public List<TemperatureData> viewTemperatureData(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewTemperatureData(tDate1,tDate2);
    }
    //查询当日光照
    @RequestMapping("/viewTodayLight")
    public List<LightData> viewLightData(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewLightData(tDate1,tDate2);
    }
    //查询每日湿度平均
    @RequestMapping("/viewDateHumidity")
    public List<HumidityData> viewDateHumidity(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewDateHumidity(tDate1,tDate2);
    }
    //查询每日温度平均
    @RequestMapping("/viewDateTemperature")
    public List<TemperatureData> viewDateTemperature(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewDateTemperature(tDate1,tDate2);
    }
    //查询每日光照平均
    @RequestMapping("/viewDateLight")
    public List<LightData> viewDateLight(@RequestParam String date1, @RequestParam String date2){
        Timestamp tDate1=null;
        Timestamp tDate2=null;
        tDate1=Timestamp.valueOf(date1);
        tDate2=Timestamp.valueOf(date2);
        return viewService.viewDateLight(tDate1,tDate2);
    }
}
